package me.lxqq.test.web;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class MessagePool {
    private static final Map<Object, LinkedList<Object>> MESSAGES = new HashMap<>();

    public static void message(Object type, Object msg) {
        LinkedList<Object> msgs = MESSAGES.get(type);
        if (msgs == null) {
            msgs = new LinkedList<>();
            MESSAGES.put(type, msgs);
        }
        msgs.add(msg);
    }

    public static <T extends Object> T message(Object type) {
        LinkedList<Object> msgs = MESSAGES.get(type);
        if (MESSAGES.get(type) == null) {
            return null;
        }
        return (T) msgs.peekFirst();
    }
}
